package ruijie;

public class Main2 {
    /**
     * 找出每个数后面比它大的最小的数
     * 最无脑，冒泡找
     */
    public int[] findNext(int[] A, int n) {
        // write code here
        int[] res = new int[n];
        for(int i=0;i<n;i++){
            res[i] = -1;
        }

        for(int i = n-2;i>=0;i--){
            int min = -1;
            for(int j = i+1;j<n;j++){
                if(A[j]>A[i]) min = (min == -1?A[j] : Math.min(min,A[j]));
            }
            res[i] = min;
        }

        return res;
    }

    public static void main(String[] args) {
        for (int i : new Main2().findNext(new int[]{11, 13, 10, 5, 12, 21, 3}, 7)) {
            System.out.println(i);
        }
    }
}
